$(function(){

	show_countdown();

  FB.init({
    appId  : fb_app_id,
    frictionlessRequests: true
  });

	$('.head_slogan.slides').slides({
		preload: true,
		preloadImage: base_url+'application/images/loader.gif',
		play: 3800,
		pause: 1000,
		slideSpeed: 1000,
		hoverPause: false,
		generatePagination:false
	});

	$("#faqs").on("click", function(){
		$("#win_infoex").css("padding-left", "25px").css("width", "600px");
		get_page('home/faqs?ho=si');
	});
	$("#about").on("click", function(){
		$("#win_infoex").css("padding-left", "25px").css("width", "600px");
		get_page('home/about?ho=si');
	});
	$("#terminos").on("click", function(){
		$("#win_infoex").css("padding-left", "25px").css("width", "600px");
		get_page('home/terminos?ho=si');
	});
	$(document).on('click', "#win_infoex .cerrar", function(){
		$("#win_infoex").css("display", "none");
	});

	$(".sec_cats .cuadro").on("click", function(){
		var cats = $(this), ancho;
		if(cats.attr("data-cat") == "precios"){
			get_page("home/precios", "win_infoex", false);
			ancho = 625;
		}else{
			get_pages_preload(cats.attr("data-cat"), "scroll_table");
			// get_page("home/articulos?ho=si&cat="+cats.attr("data-cat"), "scroll_table", true, "json");
			ancho = 625;
		}

		$("#win_infoex").css("padding-left", "0px").css("width", ancho+"px").css("overflow", "hidden");
	});

  $('#fb_invita_link').on("click", function(){
    FB.ui({method: 'apprequests',
      message: 'Te invitamos a la Tienda de conocimiento Capp.'
    }, function () {});
  });

});


function get_page(url, id, scrol, datatype){
	var loaderrr = $("#imgloadimg");
	id = id? id: "win_infoex";

	datatype = datatype? datatype: "html";

	loaderrr.show();
	$.ajax({
		type: "GET",
		dataType: datatype,
		url: base_url+url,
		success: function(data) {
			data = datatype=="html"? data: data.html;
			$('#win_infoex').html(data).css("display", "block");
			if (scrol != false)
				$('#'+id).tinyscrollbar();
		},
		complete: function(){
			loaderrr.hide();
		}
	});
}
function get_pages_preload(id, id2){
	$('#win_infoex').html($("#ocultos_"+id).html()).css("display", "block");
	$('#win_infoex #'+id2).tinyscrollbar();
	// datatype = datatype? datatype: "html";
	// $.ajax({
	// 	type: "GET",
	// 	dataType: datatype,
	// 	url: base_url+url,
	// 	success: function(data) {
	// 		data = datatype=="html"? data: data.html;
	// 		$('#win_infoex').html(data)
	// 	}
	// });
}


function faqs(){
	var obj = $("#win_infoex");
	obj.css("padding-left", "25px").css("width", "600px");
	obj.css("display", "block");
	$(".overview .cerrar").remove();
	obj.tinyscrollbar();
}

function about(){
	var obj = $("#win_infoex");
	obj.css("padding-left", "25px").css("width", "600px");
	obj.css("display", "block");
	$(".overview .cerrar").remove();
	obj.tinyscrollbar();
}

function terminos(){
	var obj = $("#win_infoex");
	obj.css("padding-left", "25px").css("width", "600px");
	obj.css("display", "block");
	$(".overview .cerrar").remove();
	obj.tinyscrollbar();
}

function articulos(){
	var obj = $("#win_infoex");
	obj.css("padding-left", "0px").css("width", "625px").css("overflow", "hidden");
	obj.css("display", "block");
	$(".overviews .cerrar").remove();
	obj.tinyscrollbar();
}



function show_countdown(){
	var ts = new Date(2013, 2, 5), hoy = new Date(),
	dife = ts.getTime() - hoy.getTime(),
	dias = Math.floor(dife / (1000 * 60 * 60 * 24));

	if ($.superbox && dias > 0){
	  $("#sb").remove();
	  sbox = '<a href="'+base_url+'home/cangea_countdown" rel="superbox[iframe][400x200]" id="sb"></a>'; // 330x422
	  $(sbox).appendTo("body");

	  $.superbox.settings = {
	    boxId: "superbox", // Id attribute of the "superbox" element
	    overlayOpacity: .9, // Background opaqueness
	    closeTxt: "Cerrar", // "Close" button text
	    closeOnClick: true,
	    closeEsc: true
	  };

	  $.superbox();

	  $('#sb').click();
	}
}